from threading import Thread
from time import ctime, sleep

loops = [2, 4]


def loop(nloop, sec):
    print('start loop', nloop, ctime())
    sleep(sec)
    print('end loop', nloop, ctime())


"""
  Thread类的使用
"""


def main():
    threads = []
    for i in range(len(loops)):
        threads.append(Thread(target=loop, args=(i, loops[i])))

    for i in range(len(loops)):
        threads[i].start()

    for i in range(len(loops)):
        threads[i].join()

    print("all method done!", ctime())


if __name__ == "__main__":
    main()
